#pragma once 
#include <time.h>
#include <stdio.h>
#include <string>

// 日志分为三个等级：调试 正常 错误
#define DEBUG  0
#define NORMAL 1
#define ERROR  2

std::string level_to_string(int level)
{
  if(level == DEBUG) return "DEBUG";
  if(level == NORMAL) return "NORMAL";
  return "ERROR";
}


// 日志的输出格式为：[年-月-日 时:分:秒][日志等级][文件与行号]：日志内容
#define LOG(level,format,...) {\
  time_t timep = time(nullptr);\
  struct tm *ptm = localtime(&timep);\
  char time_buffer[48] = {0};\
  sprintf(time_buffer,"[%d-%d-%d %d:%d:%d]",ptm->tm_year+1900,ptm->tm_mon+1,ptm->tm_mday,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);\
  char log_buffer[48] = {0};\
  sprintf(log_buffer,"[%s]",level_to_string(level).c_str());\
  fprintf(stdout,"%s%s[%s:%d]:" format "\n",time_buffer,log_buffer,__FILE__,__LINE__,##__VA_ARGS__);\
}

#define DEBUG_LOG(format,...) LOG(DEBUG,format,##__VA_ARGS__)
#define NORMAL_LOG(format,...) LOG(NORMAL,format,##__VA_ARGS__)
#define ERROR_LOG(format,...) LOG(ERROR,format,##__VA_ARGS__)
